@@ -298,16 +298,32 @@ def consumer_info_api(request):  | 
            ||
| 298 | 298 | 
                test_user=False,  | 
            
| 299 | 299 | 
                ).count() == 1:  | 
            
| 300 | 300 | 
                ymd = int(tc.local_string(format='%Y%m%d'))  | 
            
| 301 | 
                + ym = int(tc.local_string(format='%Y%m'))  | 
            |
| 302 | 
                + y = int(tc.local_string(format='%Y'))  | 
            |
| 301 | 303 | 
                 | 
            
| 302 | 
                - # 销量统计  | 
            |
| 304 | 
                + # 日销量统计  | 
            |
| 303 | 305 | 
                ssi, _ = ConsumeSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            
| 304 | 306 | 
                brand_id=brand.brand_id,  | 
            
| 305 | 307 | 
                ymd=ymd,  | 
            
| 306 | 308 | 
                )  | 
            
| 307 | 309 | 
                ssi.num += 1  | 
            
| 308 | 310 | 
                ssi.save()  | 
            
| 311 | 
                + # 月销量统计  | 
            |
| 312 | 
                + ssi, _ = ConsumeSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 313 | 
                + brand_id=brand.brand_id,  | 
            |
| 314 | 
                + ymd=ym,  | 
            |
| 315 | 
                + )  | 
            |
| 316 | 
                + ssi.num += 1  | 
            |
| 317 | 
                + ssi.save()  | 
            |
| 318 | 
                + # 年销量统计  | 
            |
| 319 | 
                + ssi, _ = ConsumeSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 320 | 
                + brand_id=brand.brand_id,  | 
            |
| 321 | 
                + ymd=y,  | 
            |
| 322 | 
                + )  | 
            |
| 323 | 
                + ssi.num += 1  | 
            |
| 324 | 
                + ssi.save()  | 
            |
| 309 | 325 | 
                 | 
            
| 310 | 
                - # 型号销量统计  | 
            |
| 326 | 
                + # 日型号销量统计  | 
            |
| 311 | 327 | 
                mssi, _ = ConsumeModelSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            
| 312 | 328 | 
                brand_id=brand.brand_id,  | 
            
| 313 | 329 | 
                model_id=model.model_id,  | 
            
                @@ -316,15 +332,33 @@ def consumer_info_api(request):  | 
            ||
| 316 | 332 | 
                mssi.model_name = model.model_name  | 
            
| 317 | 333 | 
                mssi.num += 1  | 
            
| 318 | 334 | 
                mssi.save()  | 
            
| 319 | 
                -  | 
            |
| 320 | 
                - mssi2, _ = ConsumeModelSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 335 | 
                + # 月型号销量统计  | 
            |
| 336 | 
                + mssi, _ = ConsumeModelSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 337 | 
                + brand_id=brand.brand_id,  | 
            |
| 338 | 
                + model_id=model.model_id,  | 
            |
| 339 | 
                + ymd=ym,  | 
            |
| 340 | 
                + )  | 
            |
| 341 | 
                + mssi.model_name = model.model_name  | 
            |
| 342 | 
                + mssi.num += 1  | 
            |
| 343 | 
                + mssi.save()  | 
            |
| 344 | 
                + # 年型号销量统计  | 
            |
| 345 | 
                + mssi, _ = ConsumeModelSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 321 | 346 | 
                brand_id=brand.brand_id,  | 
            
| 322 | 347 | 
                model_id=model.model_id,  | 
            
| 323 | 
                - ymd=0,  | 
            |
| 348 | 
                + ymd=y,  | 
            |
| 324 | 349 | 
                )  | 
            
| 325 | 
                - mssi2.model_name = model.model_name  | 
            |
| 326 | 
                - mssi2.num += 1  | 
            |
| 327 | 
                - mssi2.save()  | 
            |
| 350 | 
                + mssi.model_name = model.model_name  | 
            |
| 351 | 
                + mssi.num += 1  | 
            |
| 352 | 
                + mssi.save()  | 
            |
| 353 | 
                +  | 
            |
| 354 | 
                + # mssi2, _ = ConsumeModelSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 355 | 
                + # brand_id=brand.brand_id,  | 
            |
| 356 | 
                + # model_id=model.model_id,  | 
            |
| 357 | 
                + # ymd=0,  | 
            |
| 358 | 
                + # )  | 
            |
| 359 | 
                + # mssi2.model_name = model.model_name  | 
            |
| 360 | 
                + # mssi2.num += 1  | 
            |
| 361 | 
                + # mssi2.save()  | 
            |
| 328 | 362 | 
                 | 
            
| 329 | 363 | 
                # # 经销商销量统计  | 
            
| 330 | 364 | 
                # dssi, _ = ConsumeDistributorSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            
                @@ -139,14 +139,30 @@ def clerk_sale_submit_api(request):  | 
            ||
| 139 | 139 | 
                # TODO: Make statistic async  | 
            
| 140 | 140 | 
                if not sci:  | 
            
| 141 | 141 | 
                ymd = int(tc.local_string(format='%Y%m%d'))  | 
            
| 142 | 
                + ym = int(tc.local_string(format='%Y%m'))  | 
            |
| 143 | 
                + y = int(tc.local_string(format='%Y'))  | 
            |
| 142 | 144 | 
                 | 
            
| 143 | 
                - # 销量统计  | 
            |
| 145 | 
                + # 日销量统计  | 
            |
| 144 | 146 | 
                ssi, _ = SaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            
| 145 | 147 | 
                brand_id=brand.brand_id,  | 
            
| 146 | 148 | 
                ymd=ymd,  | 
            
| 147 | 149 | 
                )  | 
            
| 148 | 150 | 
                ssi.num += 1  | 
            
| 149 | 151 | 
                ssi.save()  | 
            
| 152 | 
                + # 月销量统计  | 
            |
| 153 | 
                + ssi, _ = SaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 154 | 
                + brand_id=brand.brand_id,  | 
            |
| 155 | 
                + ymd=ym,  | 
            |
| 156 | 
                + )  | 
            |
| 157 | 
                + ssi.num += 1  | 
            |
| 158 | 
                + ssi.save()  | 
            |
| 159 | 
                + # 年销量统计  | 
            |
| 160 | 
                + ssi, _ = SaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 161 | 
                + brand_id=brand.brand_id,  | 
            |
| 162 | 
                + ymd=y,  | 
            |
| 163 | 
                + )  | 
            |
| 164 | 
                + ssi.num += 1  | 
            |
| 165 | 
                + ssi.save()  | 
            |
| 150 | 166 | 
                 | 
            
| 151 | 167 | 
                # 型号销量统计  | 
            
| 152 | 168 | 
                mssi, _ = ModelSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            
                @@ -186,7 +202,7 @@ def clerk_sale_submit_api(request):  | 
            ||
| 186 | 202 | 
                dssi2.num += 1  | 
            
| 187 | 203 | 
                dssi2.save()  | 
            
| 188 | 204 | 
                 | 
            
| 189 | 
                - # 省份销量统计  | 
            |
| 205 | 
                + # 日省份销量统计  | 
            |
| 190 | 206 | 
                pssi, _ = ProvinceSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            
| 191 | 207 | 
                brand_id=brand.brand_id,  | 
            
| 192 | 208 | 
                province_code=distributor.distributor_province_code,  | 
            
                @@ -195,15 +211,33 @@ def clerk_sale_submit_api(request):  | 
            ||
| 195 | 211 | 
                pssi.province_name = distributor.distributor_province_name  | 
            
| 196 | 212 | 
                pssi.num += 1  | 
            
| 197 | 213 | 
                pssi.save()  | 
            
| 198 | 
                -  | 
            |
| 199 | 
                - pssi2, _ = ProvinceSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 214 | 
                + # 月省份销量统计  | 
            |
| 215 | 
                + pssi, _ = ProvinceSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 200 | 216 | 
                brand_id=brand.brand_id,  | 
            
| 201 | 217 | 
                province_code=distributor.distributor_province_code,  | 
            
| 202 | 
                - ymd=0,  | 
            |
| 218 | 
                + ymd=ym,  | 
            |
| 219 | 
                + )  | 
            |
| 220 | 
                + pssi.province_name = distributor.distributor_province_name  | 
            |
| 221 | 
                + pssi.num += 1  | 
            |
| 222 | 
                + pssi.save()  | 
            |
| 223 | 
                + # 年省份销量统计  | 
            |
| 224 | 
                + pssi, _ = ProvinceSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 225 | 
                + brand_id=brand.brand_id,  | 
            |
| 226 | 
                + province_code=distributor.distributor_province_code,  | 
            |
| 227 | 
                + ymd=y,  | 
            |
| 203 | 228 | 
                )  | 
            
| 204 | 
                - pssi2.province_name = distributor.distributor_province_name  | 
            |
| 205 | 
                - pssi2.num += 1  | 
            |
| 206 | 
                - pssi2.save()  | 
            |
| 229 | 
                + pssi.province_name = distributor.distributor_province_name  | 
            |
| 230 | 
                + pssi.num += 1  | 
            |
| 231 | 
                + pssi.save()  | 
            |
| 232 | 
                +  | 
            |
| 233 | 
                + # pssi2, _ = ProvinceSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 234 | 
                + # brand_id=brand.brand_id,  | 
            |
| 235 | 
                + # province_code=distributor.distributor_province_code,  | 
            |
| 236 | 
                + # ymd=0,  | 
            |
| 237 | 
                + # )  | 
            |
| 238 | 
                + # pssi2.province_name = distributor.distributor_province_name  | 
            |
| 239 | 
                + # pssi2.num += 1  | 
            |
| 240 | 
                + # pssi2.save()  | 
            |
| 207 | 241 | 
                 | 
            
| 208 | 242 | 
                     return response(200, data={
               | 
            
| 209 | 243 | 
                'integral': integral,  | 
            
                @@ -8,8 +8,8 @@ from pysnippets.strsnippets import strip  | 
            ||
| 8 | 8 | 
                 | 
            
| 9 | 9 | 
                from mch.models import BrandInfo, DistributorInfo, ModelInfo  | 
            
| 10 | 10 | 
                from statistic.models import (ConsumeDistributorSaleStatisticInfo, ConsumeModelSaleStatisticInfo,  | 
            
| 11 | 
                - ConsumeProvinceSaleStatisticInfo, DistributorSaleStatisticInfo, ModelSaleStatisticInfo,  | 
            |
| 12 | 
                - ProvinceSaleStatisticInfo)  | 
            |
| 11 | 
                + ConsumeProvinceSaleStatisticInfo, ConsumeSaleStatisticInfo, DistributorSaleStatisticInfo,  | 
            |
| 12 | 
                + ModelSaleStatisticInfo, ProvinceSaleStatisticInfo, SaleStatisticInfo)  | 
            |
| 13 | 13 | 
                 | 
            
| 14 | 14 | 
                 | 
            
| 15 | 15 | 
                 PROVINCE_LIST = {
               | 
            
                @@ -136,3 +136,63 @@ def pre_new_models(fpath='./pre/static/models_20180816.xls'):  | 
            ||
| 136 | 136 | 
                mdl.model_full_name = strip(rvals[4])  | 
            
| 137 | 137 | 
                mdl.warehouse = strip(rvals[5])  | 
            
| 138 | 138 | 
                mdl.save()  | 
            
| 139 | 
                +  | 
            |
| 140 | 
                +  | 
            |
| 141 | 
                +def fill_ym():  | 
            |
| 142 | 
                + for o in ConsumeSaleStatisticInfo.objects.all():  | 
            |
| 143 | 
                + ymd = str(o.ymd)  | 
            |
| 144 | 
                + if len(ymd) == 8:  | 
            |
| 145 | 
                + # 月销量统计  | 
            |
| 146 | 
                + ssi, _ = ConsumeSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 147 | 
                + brand_id=o.brand_id,  | 
            |
| 148 | 
                + ymd=ymd[6],  | 
            |
| 149 | 
                + )  | 
            |
| 150 | 
                + ssi.num += 1  | 
            |
| 151 | 
                + ssi.save()  | 
            |
| 152 | 
                + # 年销量统计  | 
            |
| 153 | 
                + ssi, _ = ConsumeSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 154 | 
                + brand_id=o.brand_id,  | 
            |
| 155 | 
                + ymd=ymd[4],  | 
            |
| 156 | 
                + )  | 
            |
| 157 | 
                + ssi.num += 1  | 
            |
| 158 | 
                + ssi.save()  | 
            |
| 159 | 
                +  | 
            |
| 160 | 
                + for o in ConsumeModelSaleStatisticInfo.objects.all():  | 
            |
| 161 | 
                + ymd = str(o.ymd)  | 
            |
| 162 | 
                + if len(ymd) == 8:  | 
            |
| 163 | 
                + # 月型号销量统计  | 
            |
| 164 | 
                + mssi, _ = ConsumeModelSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 165 | 
                + brand_id=o.brand_id,  | 
            |
| 166 | 
                + model_id=o.model_id,  | 
            |
| 167 | 
                + ymd=ymd[6],  | 
            |
| 168 | 
                + )  | 
            |
| 169 | 
                + mssi.model_name = o.model_name  | 
            |
| 170 | 
                + mssi.num += 1  | 
            |
| 171 | 
                + mssi.save()  | 
            |
| 172 | 
                + # 年型号销量统计  | 
            |
| 173 | 
                + mssi, _ = ConsumeModelSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 174 | 
                + brand_id=o.brand_id,  | 
            |
| 175 | 
                + model_id=o.model_id,  | 
            |
| 176 | 
                + ymd=ymd[4],  | 
            |
| 177 | 
                + )  | 
            |
| 178 | 
                + mssi.model_name = o.model_name  | 
            |
| 179 | 
                + mssi.num += 1  | 
            |
| 180 | 
                + mssi.save()  | 
            |
| 181 | 
                +  | 
            |
| 182 | 
                + for o in SaleStatisticInfo.objects.all():  | 
            |
| 183 | 
                + ymd = str(o.ymd)  | 
            |
| 184 | 
                + if len(ymd) == 8:  | 
            |
| 185 | 
                + # 月销量统计  | 
            |
| 186 | 
                + ssi, _ = SaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 187 | 
                + brand_id=o.brand_id,  | 
            |
| 188 | 
                + ymd=ymd[6],  | 
            |
| 189 | 
                + )  | 
            |
| 190 | 
                + ssi.num += 1  | 
            |
| 191 | 
                + ssi.save()  | 
            |
| 192 | 
                + # 年销量统计  | 
            |
| 193 | 
                + ssi, _ = SaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 194 | 
                + brand_id=o.brand_id,  | 
            |
| 195 | 
                + ymd=ymd[4],  | 
            |
| 196 | 
                + )  | 
            |
| 197 | 
                + ssi.num += 1  | 
            |
| 198 | 
                + ssi.save()  | 
            
                @@ -1,4 +1,4 @@  | 
            ||
| 1 | 
                -Django==1.11.15  | 
            |
| 1 | 
                +Django==1.11.16  | 
            |
| 2 | 2 | 
                django-admin==1.3.2  | 
            
| 3 | 3 | 
                django-cors-headers==2.4.0  | 
            
| 4 | 4 | 
                django-curtail-uuid==1.0.4  | 
            
                @@ -205,7 +205,7 @@ def __tj_generate(ymd=None):  | 
            ||
| 205 | 205 | 
                 | 
            
| 206 | 206 | 
                 | 
            
| 207 | 207 | 
                def ymdtj(brand_id, ymd, lastymd):  | 
            
| 208 | 
                - # 周期内扫描用户人数  | 
            |
| 208 | 
                + # [消费者维度] 周期内扫描用户人数  | 
            |
| 209 | 209 | 
                try:  | 
            
| 210 | 210 | 
                scan_user_count = ConsumeSaleStatisticInfo.objects.get(brand_id=brand_id, ymd=ymd).num  | 
            
| 211 | 211 | 
                except ConsumeSaleStatisticInfo.DoesNotExist:  | 
            
                @@ -219,7 +219,7 @@ def ymdtj(brand_id, ymd, lastymd):  | 
            ||
| 219 | 219 | 
                # 与上个统计周期数据的用户人数比例  | 
            
| 220 | 220 | 
                user_count_increase_pct = '%.2f' % (scan_user_count * 100.0 / last_scan_user_count) if last_scan_user_count != 0 else 0  | 
            
| 221 | 221 | 
                 | 
            
| 222 | 
                - # 周期内镜头销售支数  | 
            |
| 222 | 
                + # [经销商维度] 周期内镜头销售支数  | 
            |
| 223 | 223 | 
                try:  | 
            
| 224 | 224 | 
                sell_volume_count = SaleStatisticInfo.objects.get(brand_id=brand_id, ymd=ymd).num  | 
            
| 225 | 225 | 
                except SaleStatisticInfo.DoesNotExist:  | 
            
                @@ -233,15 +233,15 @@ def ymdtj(brand_id, ymd, lastymd):  | 
            ||
| 233 | 233 | 
                # 与上个统计周期数据的销售支数比例  | 
            
| 234 | 234 | 
                volume_count_increase_pct = '%.2f' % (sell_volume_count * 100.0 / last_sell_volume_count) if last_sell_volume_count != 0 else 0  | 
            
| 235 | 235 | 
                 | 
            
| 236 | 
                - # 统计周期内型号扫描排行数据,请按顺序返回  | 
            |
| 236 | 
                + # [消费者维度] 统计周期内型号扫描排行数据,请按顺序返回  | 
            |
| 237 | 237 | 
                     models = ConsumeModelSaleStatisticInfo.objects.filter(brand_id=brand_id, ymd=ymd, status=True).order_by('-num')[:20]
               | 
            
| 238 | 238 | 
                models = [m.data for m in models]  | 
            
| 239 | 239 | 
                 | 
            
| 240 | 
                - # 统计周期内销售员排行数据,请按顺序返回  | 
            |
| 240 | 
                + # [经销商维度] 统计周期内销售员排行数据,请按顺序返回  | 
            |
| 241 | 241 | 
                     salesmen = SaleclerkSaleStatisticInfo.objects.filter(brand_id=brand_id, ymd=ymd, status=True).order_by('-num')[:20]
               | 
            
| 242 | 242 | 
                salesmen = [s.data for s in salesmen]  | 
            
| 243 | 243 | 
                 | 
            
| 244 | 
                - # 统计周期内省份销量排行数据,请按顺序返回  | 
            |
| 244 | 
                + # [经销商维度] 统计周期内省份销量排行数据,请按顺序返回  | 
            |
| 245 | 245 | 
                provinces = ProvinceSaleStatisticInfo.objects.filter(brand_id=brand_id, ymd=ymd, status=True)  | 
            
| 246 | 246 | 
                provinces = [p.data for p in provinces]  | 
            
| 247 | 247 | 
                 |